function [ output_args ] = TFC2_CreateStats( input_args )
%TFC2_CREATESTATS Adds statistics to the tfc data

global Database;

%% Set up environment
cFilename = strcmp(Database.tfc_header, 'Filename');
cSubjects = strcmp(Database.tfc_header, 'Subjects');
cConditions = strcmp(Database.tfc_header, 'Conditions');
cFrequencyBins = strcmp(Database.tfc_header, 'FrequencyBins');
cBaselineSettings = strcmp(Database.tfc_header, 'BaselineSettings');
cTimes = strcmp(Database.tfc_header, 'Times');

%% Do it
for row = 1:size(Database.tfc,1)
    if row == 1
        frequencyBins = Database.tfc{row,cFrequencyBins};
        baselineSettings = Database.tfc{row,cBaselineSettings};
        times = Database.tfc{row,cTimes};
    else
        % Check to see if the frequencybins, baselinesettings and times are
        % all the same...
        warning('Frequencybins, baselinesettings and times are not checked.');
    end

    filename = Database.tfc{row,cFilename};
    load(filename,'-mat');
    
    for sIdx = fieldnames(data)'
        subject = sIdx{1};
        for chIdx = fieldnames(data.(subject))'
            channel = chIdx{1};
            for coIdx = fieldnames(data.(subject).(channel))'
                condition = coIdx{1};

                disp(['Adding statistics: ' subject '/' channel '/' condition]);

                [h,p_values,ci,stats] = ttest(data.(subject).(channel).(condition).power, 1, [], [], 3);
                data.(subject).(channel).(condition).ttest.h = h;
                data.(subject).(channel).(condition).ttest.p_values = p_values;
                data.(subject).(channel).(condition).ttest.ci = ci;
                data.(subject).(channel).(condition).ttest.stats = stats;
            end
        end
    end
    
    save(filename, 'data', 'frequencyBins', 'baselineSettings', 'times', '-v7.3');
    
end


end

